<template>
  <!-- // 分配角色 -->
  <div>
    <el-checkbox-group v-model="roleIds">
      <el-checkbox v-for="item in rolesList" :key="item.id" :label="item.id">{{ item.name }}</el-checkbox>
    </el-checkbox-group>

    <div style="margin-top: 20px; text-align: right">
      <el-button type="primary" @click="hAssignRole">确定</el-button>
      <el-button @click="$emit('close')">取消</el-button>
    </div>
  </div>
</template>
<script>
import { getRoles } from '@/api/settings'
import { staffPhoto } from '@/api/user'
import { updataAssignRoles } from '@/api/employess'
export default {
  props: {
    id: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      roleIds: [],
      rolesList: [] // 已有权限列表
    }
  },
  created() {
    this.loadRoles()
  },
  methods: {
    // 根据id更新角色
    async hAssignRole() {
      try {
        const res = await updataAssignRoles({ roleIds: this.roleIds, id: this.id })
        console.log(res, 'updataAssignRoles')
        this.$emit('close')
      } catch (error) {
        console.log(error)
      }
    },
    // 获取角色详情 获取权限列表
    async loadRoles() {
      try {
        const res = await getRoles()
        this.rolesList = res.data.rows
        // console.log('getRoles', res)
        const info = await staffPhoto(this.id)
        console.log(info, 'infoooooooooo')
        this.roleIds = info.data.roleIds || []
        // 保存数据
      } catch (err) {
        console.log('getRoles', err)
      }
    }
  }
}
</script>
